package me.heizi.springboot.students.config

import me.heizi.springboot.students.entities.UserTypeKv
import me.heizi.springboot.students.model.UserType
import me.heizi.springboot.students.repositories.UserTypeRepository
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component

@Component
object GlobalBeans {


    @Bean(name = ["userTypes"]) fun types(types:UserTypeRepository): List<UserType> = types
        .selectList(null)
        .map { data-> UserType.found(data.id) }

    fun Collection<UserType>.findByName(name:String) = find { it.chineseName == name || it::class.simpleName == name }
}